﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Discuz.Forum;
using Discuz.Entity;

namespace Discuz.Web
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (System.Configuration.ConfigurationManager.AppSettings["hidecall"].ToString() != "true")
            {
                string url = Request.Url.ToString();
                string a = Request.PathInfo;
                if (url.IndexOf(".aspx") == -1)
                    return;
                string usernames = string.Empty;
                if (url.IndexOf("register.aspx") == -1 && url.IndexOf("login.aspx") == -1 && url.IndexOf("getpassword.aspx") == -1 && url.IndexOf("VerifyImagePage.aspx") == -1 && url.IndexOf("logout.aspx") == -1)
                {
                    string path = ("~/login.aspx");
                    if (Request.Cookies["dnt"] != null)
                    {
                        HttpCookie user = Request.Cookies["dnt"];
                        int uid = Convert.ToInt32(user["userid"]);
                        UserInfo usinfo = Users.GetUserInfo(uid);
                        if (usinfo != null)
                        {
                            usernames = usinfo.Username;
                            if (AdminUsers.GetUserId(usernames) <= 0)
                            {
                                Response.Redirect(path);
                            }
                        }
                        else
                        {
                            Response.Redirect(path);
                        }
                    }
                    else
                    {
                        Response.Redirect(path);
                    }
                }
            }
        }
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}